/**
 * OSAmI: Open Source Ambient Intelligence
 * Copyright (C) 2010 UJF.
 * Contact: osami-general@osami-commons.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 */
package org.osami.gateway.mediator.sensedata.internal;

import fr.liglab.adele.cilia.Data;
import org.osami.gateway.sensor.data.SenseData;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: guillaume
 * Date: 12/08/11
 * Time: 15:19
 * To change this template use File | Settings | File Templates.
 */
public class SenseDataMapTransformer {

    /**
     * Transform the given SenseData instance into a Serializable Map.
     * @param data input data containing the sense data
     * @return output data with a Map
     */
    public Data process(Data data) {
        SenseData sd = (SenseData) data.getProperty(SenseData.DEFAULT_DATA_KEY);
        Map<String, Serializable> map = new HashMap<String, Serializable>();

        map.put("location", sd.getLocation());
        map.put("sense.id", sd.getSenseId());
        map.put("timestamp", sd.getTimeStamp());
        map.put("type", sd.getType());
        map.put("unit", sd.getUnit());
        map.put("value", sd.getValue());

        return new Data(map, null, null);

    }
}
